package org.phalanx.xml;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;

/*
 * This class encapsulates XML tags and data associated with it
 * 
 * 
 * */
public class XMLObject implements Comparable{
	private String parentTag;
	private String xmlTag;
	private String storedData;
	private Hashtable<String,String> attributes = new Hashtable<String,String>();
	private int weight = 0;
	
	public XMLObject(String xmlTag,String parentTag, String storedData){
		this.setParentTag(parentTag);
		this.setXmlTag(xmlTag);
		this.setStoredData(storedData);
	}
	
	public XMLObject(String xmlTag, String parentTag){
		this.setParentTag(parentTag);
		this.setXmlTag(xmlTag);
	}
	
	public XMLObject(String xmlTag){
		this.setParentTag(xmlTag);
	}
	
	public XMLObject(){
		this.setParentTag(new String());
		this.setStoredData(new String());
		this.setXmlTag(new String());
	}

	public String getParentTag() {
		return parentTag;
	}

	public void setParentTag(String parentTag) {
		this.parentTag = parentTag;
	}

	public String getXmlTag() {
		return xmlTag;
	}

	public void setXmlTag(String xmlTag) {
		this.xmlTag = xmlTag;
	}

	public String getStoredData() {
		return storedData;
	}

	public void setStoredData(String storedData) {
		this.storedData = storedData;
	}
	
	public void setAttribute(String attrName, String attrValue){
		attributes.put(attrName, attrValue == null ? "" : attrValue);
	}
	
	public String getAttributes(String attrName){
		return attributes.get(attrName);
	}
	
	public ArrayList<String> getAttributesList(){
		ArrayList<String> a = new ArrayList<String>();
		
		Enumeration<String> e = attributes.keys();
		
		while(e.hasMoreElements()){
			a.add(e.nextElement());
		}
		
		return a;
	}
	
	public int getWeight(){
		return weight;
	}
	
	public void setWeight(int weight){
		this.weight = weight;
	}

	public int compareTo(Object arg0) {
		XMLObject comparedObject = (XMLObject)arg0;
		
		return comparedObject.getWeight() - weight;
	}
}
